package cdu.sl.aop;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Component
@Aspect
public class MyAspect1 {
    private static final Logger log = LoggerFactory.getLogger(MyAspect1.class);
    // 可以使用逻辑运算符来进行匹配
    @Before("execution( * cdu.sl.service.impl.DeptServiceImpl.getById(..))")
    public void before(JoinPoint joinPoint) {
        log.info("MyAspect5--->before");

        // 1.获取目标对象
        Object target = joinPoint.getTarget();
        log.info("获取目标对象：{}", target);

        // 2.获取目标类
        String className = joinPoint.getTarget().getClass().getName();
        log.info("获取目标类：{}", className);

        // 3.获取目标方法
        String methodName = joinPoint.getSignature().getName();
        log.info("获取目标方法：{}", methodName);

        // 4.获取目标方法参数
        Object[] args = joinPoint.getArgs();
        log.info("获取到目标方法参数：{}", Arrays.toString(args));
    }
}
